package com.talkyun.openx.server.helper;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class VersionHelper {
    private static String version = "2.6.5";

    public static String getOpenxVersion() {
        if (version == null) {
            try {
                version = readOpenxVersion();
            } catch (Exception e) {
                version = "error";
            }
        }
        return version;
    }

    private static String readOpenxVersion() throws IOException {
        String path = "/META-INF/maven/com.talkyun/openx-client/pom.properties";
        InputStream ins = VersionHelper.class.getResourceAsStream(path);

        try {
            Properties p = new Properties();
            p.load(ins);
            return p.getProperty("version").toLowerCase();
        } finally {
            ins.close();
        }
    }
}